package com.hbnu.tangyalu;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Random;

public class DouDiZhu {
    public static void main(String[] args) {
        String[] flower = {"黑桃", "红心", "方块", "梅花"};
        String[] num = {"2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A"};
        List<String> pokers = new ArrayList<>();
        for (String flowers : flower) {
            for (String number : num) {
                pokers.add(flowers + number);
            }
        }
//        System.out.println(pokers);
        pokers.add("大王");
        pokers.add("小王");
//        System.out.println(pokers.size());

//        随机洗牌
        Collections.shuffle(pokers);
        List<String> player1 = new ArrayList<>(20);
        List<String> player2 = new ArrayList<>(20);
        List<String> player3 = new ArrayList<>(20);
//        地主最后三张牌
        List<String> dizhupai = new ArrayList<>(3);
        for (int i = 0; i < pokers.size(); i++) {
            //前三张为底牌
            if (i < 3) {
                dizhupai.add(pokers.get(i));
            } else if (i % 3 == 0) {
                player1.add(pokers.get(i));
            } else if (i % 3 == 1) {
                player2.add(pokers.get(i));
            } else {
                player3.add(pokers.get(i));
            }
        }

//        随机抽出一张牌为地主牌，判断谁是地主
        Random random = new Random();
//        生成索引在54内的随机数，索引找牌
        int rdnum = random.nextInt(54);
        int dizhu = 1;
        if (rdnum < 17) {
            player1.addAll(dizhupai);
        } else if (rdnum < 34) {
            player2.addAll(dizhupai);
            dizhu = 2;
        } else {
            player3.addAll(dizhupai);
            dizhu = 3;
        }
//        System.out.println("三张地主牌为:" + dizhupai);
//        System.out.println("地主为player" + dizhu);
//        System.out.println("player1的牌一共有" + player1.size() + "张，牌为:" + player1);
//        System.out.println("player2的牌一共有" + player2.size() + "张，牌为:" + player2);
//        System.out.println("player3的牌一共有" + player3.size() + "张，牌为:" + player3);
//
        lookPoker("zzx", player1);
        lookPoker("tyl", player2);
        lookPoker("yzj", player3);
        lookPoker("底牌", dizhupai);


    }

    private static void lookPoker(String name, List<String> poker) {
        System.out.println(name + "牌是:");
        for (String pokerr : poker) {
            System.out.print(pokerr + "  ");

        }
        System.out.println();

    }
}
